<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>卡牌自走棋游戏</title>
    <link rel="stylesheet" href="css/index_style.css">
    <link rel="icon" href="logo.svg" type="image/svg+xml">
</head>

<body>
    <div class="container">
        <div class="progress">
            <h2>当前进度：第 <span id="currentLevel">1</span> 关</h2>
        </div>
        <div class="button-container">
            <button class="game-button" onclick="navigateTo('level')">关卡模式</button>
            <button class="game-button" onclick="navigateTo('random')">随机模式</button>
            <button class="game-button" onclick="navigateTo('deck-shop')">卡组商店</button>
            <button class="game-button" onclick="navigateTo('character-shop')">角色商店</button>
            <button class="game-button" onclick="navigateTo('deck-bag')">卡牌背包</button>
        </div>
    </div>

    <script>
        // 页面加载时获取当前进度
        window.onload = function () {
            fetchCurrentProgress();
        };

        // 获取当前进度
        function fetchCurrentProgress() {
            fetch('/api/game/progress')
                .then(response => response.json())
                .then(data => {
                    document.getElementById('currentLevel').textContent = data.level;
                })
                .catch(error => {
                    console.error('获取进度失败:', error);
                });
        }

        // 页面导航
        function navigateTo(page) {
            switch (page) {
                case 'level':
                    window.location.href = 'select-deck.html?mode=level';
                    break;
                case 'random':
                    window.location.href = 'select-deck.html?mode=random';
                    break;
                case 'deck-shop':
                    window.location.href = 'deck-shop.html';
                    break;
                case 'character-shop':
                    window.location.href = 'character-shop.html';
                    break;
                case 'deck-bag':
                    window.location.href = 'deck-bag.html';
                    break;
            }
        }
    </script>
</body>

</html>